package actor.persistencefsm

/**
 * Created by DJJ on 2020/1/3.
 */
package persistentfsm.tracker
import akka.actor._
import persistentfsm.cart.WebShopping
object EventTracker {
  def props = Props(new EventTracker)
}
class EventTracker extends Actor {
  override def preStart(): Unit = {
    context.system.eventStream.subscribe(self,classOf[WebShopping.CurrentCart])
    super.preStart()
  }

  override def postStop(): Unit = {
    context.system.eventStream.unsubscribe(self)
    super.postStop()
  }

  override def receive: Receive = {
    case WebShopping.CurrentCart(loc,cart) =>
      println(loc)
      cart match {
        case WebShopping.EmptyCart => println("empty cart!")
        case WebShopping.LoadedCart(items) => println(s"Current content in cart: $items")
      }
  }

}
